#ifndef _VOL_OSS_CLIENT_H
#define _VOL_OSS_CLIENT_H

#include <alibabacloud\oss\OssClient.h>
#include <alibabacloud\oss\client\RateLimiter.h>
#include <fstream>

using namespace AlibabaCloud::OSS;

//限速类
class UserRateLimiter : public RateLimiter
{
	private :
		int userRate;
		
	public :
		inline_ UserRateLimiter()
		{
			userRate = 0;
		}
		
		virtual void setRate(int rate) override { userRate = rate; }
		virtual int Rate() const override { return userRate; }
};

//客户端类
class COssClientWraper
{

	private :
		std::shared_ptr<OssClient> pClient;
		std::shared_ptr<RateLimiter> sendRateLimiter;
		std::shared_ptr<RateLimiter> recvRateLimiter;
		OssError error;
	
	public:
		ClientConfiguration configuration;
		
		COssClientWraper() 
		{
			pClient = NULL;
			sendRateLimiter = std::make_shared<UserRateLimiter>();
			recvRateLimiter = std::make_shared<UserRateLimiter>();
			configuration.sendRateLimiter = sendRateLimiter;	//持久引用,运行过程中可设置.
			configuration.recvRateLimiter = recvRateLimiter;
		}

		void InitializeClient(const CVolString& endpoint, const CVolString& accessKeyId, const CVolString& accessKeySecret, 
                                const CVolString& securityToken)
								{
									if (pClient == NULL)
									{
										CU8String u8endpoint(endpoint.GetText());
										CU8String u8accessKeyId(accessKeyId.GetText());
										CU8String u8accessKeySecret(accessKeySecret.GetText());
										CU8String u8securityToken(securityToken.GetText());
										pClient = std::make_shared<OssClient>(u8endpoint.GetText(), u8accessKeyId.GetText(), u8accessKeySecret.GetText(), u8securityToken.GetText(), configuration);
									}
								}
								
		inline_ std::shared_ptr<OssClient> GetClient()
		{
			return pClient;
		}
		
		inline_ void SetLastError(OssError err)
		{
			error = err;
		}
		
		inline_ OssError& GetLastError()
		{
			return error;
		}
};

class CBucketWraper
{
	private :
		Bucket mBucket;
		
	public :
	inline_ void SetBucket(Bucket bucket)
	{
		mBucket = bucket;
	}
	
	inline_ Bucket GetBucket()
	{
		return mBucket;
	}
};

class CBucketInfoWraper
{
	private :
		GetBucketInfoResult mBucketInfo;
		
	public :
	inline_ void SetBucketInfo(GetBucketInfoResult bucketInfo)
	{
		mBucketInfo = bucketInfo;
	}
	
	inline_ GetBucketInfoResult GetBucketInfo()
	{
		return mBucketInfo;
	}
};

class CObjectSummaryWraper
{
	private :
		ObjectSummary mObject;
		
	public :
	inline_ void SetObjectInfo(ObjectSummary obj)
	{
		mObject = obj;
	}
	
	inline_ ObjectSummary GetObjectInfo()
	{
		return mObject;
	}
};

#endif /* _VOL_OSS_CLIENT_H */